﻿@using FujiyBlog.Core.Caching
@using FujiyBlog.Core.DomainObjects
@using FujiyBlog.Core.EntityFramework
@using Newtonsoft.Json.Linq

@model WidgetSetting
@{
    Layout = "Widget.cshtml";

        JObject settings = JObject.Parse(Model.Settings??"{}");

    PostRepository postRepository = DependencyResolver.Current.GetService<PostRepository>();
    IEnumerable<Category> categories = CacheHelper.FromCacheOrExecute(() => DependencyResolver.Current.GetService<FujiyBlogDatabase>().Categories.OrderBy(x => x.Name).ToList(), "Widget.Categories.OrderBy.Name");

}
<h4>@Html.Raw(settings.Value<string>("Title") ?? "Categories")</h4>
<div class="content">
    <ul id="categorylist">
    @foreach (var category in categories)
    {
        int postsCount = CacheHelper.FromCacheOrExecute(() => postRepository.GetTotal(null, category.Name, null, null, null), "Widget.Categories.PostRepository.GetTotal." + category.Name + " as " + User.Identity.Name);
        
        <li>@Html.ActionLink(category.Name + "(" + postsCount + ")", MVC.Post.Category(category.Name, null))</li>    
    }    
    </ul>
</div>
